//
//  SCRadioPlayViewController.m
//  LastOne
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCRadioPlayViewController.h"
#import "HTTPMethod.h"
#import "Music.h"
#import "UIImage+GaussianBlur.h"
#import "CoreDataManager.h"
#import "GiFHUD.h"
#import "FitHeader.h"
@interface SCRadioPlayViewController ()
@property(nonatomic, strong)NSMutableArray *dataSourceArray;
//@property(nonatomic, strong)CoreDataManager *manager;

@end

@implementation SCRadioPlayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _radioModel.tname;
    //获取单例的manager对象赋值给当前VC的manager
    //_manager = [CoreDataManager shareManager];
    //NSLog(@"%@", [_manager applicationDocumentsDirectory]);
}
- (void)loadView
{
    [super loadView];
    [self getData];
     _radioPlayView = [[SCRadioPlayView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)];
    [self.view addSubview:_radioPlayView];
    //添加播放/暂停手势
    _radioPlayView.userInteractionEnabled = YES;
 
    //加载页面
   [GiFHUD setGifWithImageName:@"loading.gif"];
}

- (void)getData
{
    [GiFHUD show];
    self.dataSourceArray = [NSMutableArray array];
    [HTTPMethod getDataByString:[NSString stringWithFormat:@"http://c.m.163.com/nc/article/list/%@/20-20.html", _radioModel.tid] BodyDic:nil WithDataBlock:^(id data) {
        for (NSDictionary *dic in [data objectForKey:_radioModel.tid]) {
            SCRadioModel *radioModel = [[SCRadioModel alloc] init];
            [radioModel setValuesForKeysWithDictionary:dic];
            [_dataSourceArray addObject:radioModel];
        }
        _radioPlayView.dataSourceArray = _dataSourceArray;
        _radioPlayView.radioModel = _radioModel;
        
        //高斯模糊处理时间比较长,有延时效果,放的位置要慎重
        _radioPlayView.bigImageView.image = [UIImage imageWithBlurImage:[UIImage imageNamed:@"playBackground"] intputRadius:3];
        [GiFHUD dismiss];
    }];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"radio" object:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
